package com.example.goodpet.home.homeRecommend.adapter.adapters;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.GridLayoutHelper;
import com.bumptech.glide.Glide;
import com.example.goodpet.R;
import com.example.goodpet.bean.MainChannelInfoDTO;
import com.example.goodpet.home.homeRecommend.bean.ResultBeanData;
import com.example.goodpet.home.homeRecommend.fragment.HomeRecommendFragment;
import com.example.goodpet.utils.Constants;

import java.util.List;

public class MainChannelAdapter extends BaseAdapter {

    private final Context mContext;
    private final List<MainChannelInfoDTO> datas;

    public MainChannelAdapter(Context mContext, List<MainChannelInfoDTO> mainChannelInfo) {
        this.mContext=mContext;
        this.datas=mainChannelInfo;
    }


    @Override
    public int getCount() {
//        Log.e("TAG", "getCount: "+datas.size());
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView=View.inflate(mContext, R.layout.item_channel_main,null);
            viewHolder=new ViewHolder();
            viewHolder.iv_icon=convertView.findViewById(R.id.iv_main_channel);
            viewHolder.tv_title=convertView.findViewById(R.id.tv_main_channel);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }

        //根据位置得到相应的数据
        MainChannelInfoDTO mainChannelInfoDTO=datas.get(position);
//        Log.e("TAG", "getView: "+Constants.BASE_URL_IMAGE+mainChannelInfoDTO.getImage() );
        Glide.with(mContext).
                load(Constants.BASE_URL_IMAGE+mainChannelInfoDTO.getImage())
                .into(viewHolder.iv_icon);
        viewHolder.tv_title.setText(mainChannelInfoDTO.getChannelName());


        return convertView;
    }
    static class ViewHolder{
        ImageView iv_icon;
        TextView tv_title;

    }
}
